package com.hospital.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.hospital.bo.EmployeeBo;
import com.hospital.entity.Employee;
import com.hospital.service.intf.EmployeeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component()
@Scope("prototype")     // 注意 这里要设置成多例模式
public class WebEmployeeListener extends AnalysisEventListener<EmployeeBo> {

    @Autowired
    EmployeeService employeeService;

    @Override
    public void invoke(EmployeeBo employeeBo, AnalysisContext analysisContext) {
        System.out.println(employeeBo);
        Employee employee = new Employee();
        //student.setName(data.getName());
        // 属性拷贝
        BeanUtils.copyProperties(employeeBo,employee);
        employeeService.add(employee);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }


}
